import json
import pickle

import redis

from example04 import Dept

redis_cli = redis.Redis(host='47.104.31.138',
                        port=5489,
                        password='1Qaz2Wsx')
# print(redis_cli)
print(redis_cli.ping())
print(redis_cli.ttl('username'))
print(redis_cli.get('username'))
redis_cli.expire('username', 1800)
dept = Dept(110, '产品运营部', '昆明')
redis_cli.set('python2004:pickle:dept:110', pickle.dumps(dept))
redis_cli.set('python2004:json:dept:110', json.dumps(dept.__dict__))
data = redis_cli.get('python2004:json:dept:110')
print(data.decode())
# data = redis_cli.get('python2004:dept:110')
# if data:
#     dept = pickle.loads(data)
#     print(type(dept))
#     print(dept)
#     # Redis命令del ---> Redis对象的方法delete
#     redis_cli.delete('python2004:dept:110')
print(redis_cli.hvals('stu:1002'))
